Engine.Canvas = function(id, width, height)
 {
    var canvas = document.getElementById(id);
    if (width)
    canvas.width = width;
    if (height)
    canvas.height = height;

    this.width = canvas.width;
    this.height = canvas.height;

    this.context = canvas.getContext("2d");
    this.imageData = this.context.createImageData(canvas.width, canvas.height);
}

Engine.Canvas.prototype.flush = function()
{
    this.context.putImageData(this.imageData, 0, 0);
}

Engine.Canvas.prototype.setPixel = function(x, y, r, g, b, a) {
    if (x < 0 || y < 0 || x >= this.imageData.width || y >= this.imageData.height)
    return;
    var index = (x + y * this.imageData.width) * 4;
    this.imageData.data[index + 0] = r;
    this.imageData.data[index + 1] = g;
    this.imageData.data[index + 2] = b;
    this.imageData.data[index + 3] = a;
}